﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using Agnes.Core;
using Caliburn.Micro;

namespace Agnes.MyDocsLib
{
    public class RenameCmd
    {
        private static RenameCmd _instance;

        /// <summary>
        /// 返回唯一实例
        /// </summary>
        public static RenameCmd Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new RenameCmd();
                }
                return _instance;
            }
        }

        private RoutedCommand _requery;

        /// <summary>
        /// 是否能执行
        /// </summary>
        public bool CanExcuted { get; set; }

        RenameCmd()
        {
            CanExcuted = false;
            _requery = new RoutedCommand("Catalog Rename Cmd", typeof(RenameCmd));
        }

        /// <summary>
        /// 浏览文章的路由命令
        /// </summary>
        public static RoutedCommand Requery
        {
            get
            {
                return Instance._requery;
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Excuted(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                if (MyDocsLibManager.Instance.ArticleManager.SelectedNode is Catalog)
                {
                    IWindowManager wm = IoC.Get<IWindowManager>();
                    wm.ShowDialog(new ChangeTitleViewModel(MyDocsLibManager.Instance.ArticleManager.SelectedNode as Catalog));
                }
            }
            catch (Exception ex)
            {
                AgnesServiceManager.LogServ.Error("MyDocsLib--重命名失败，错误：" + ex.Message);
            }
        }

        /// <summary>
        /// 判断是否能执行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void CanExcute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (AgnesServiceManager.AgnesSlnService.CurrentSln == null
                || !(MyDocsLibManager.Instance.ArticleManager.SelectedNode is Catalog))
            {
                e.CanExecute = false;
            }
            else
            {
                e.CanExecute = true;
            }
        }
    }
}
